package com.sg.hms.controller;

import java.io.IOException;
import java.io.Writer;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sg.hms.Service.RoomService;
import com.sg.hms.ServiceImpl.RoomServiceImpl;
/***
 * 获得器材编号
 * @author 吴磊
 *
 */
public class GetEidController extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		int temp=0;
		req.setCharacterEncoding("UTF-8");
		String rid=req.getParameter("rid");
		String string = req.getParameter("qicai");
		RoomService room = new RoomServiceImpl();
		if(rid==""){
		temp = room.getEidByEid(string);
		}else {
			int rId=Integer.parseInt(rid);
			int eId=room.getEidByEid(string);
			int s=room.exixt(rId, eId);
			if (s!=0) {
				temp=100;
			}else {
				temp=room.getEidByEid(string);
			}
		}
		Writer writer = resp.getWriter();
		writer.write(String.valueOf(temp));
		writer.flush();
		writer.close();
	}

}
